{% extends "exam_system/base_exam.html" %}
{% load exam_filters %}

{% block title %}考试结果 - {{ exam_room.name }}{% endblock %}

{% block content %}
<div class="container py-4">
    <div class="row">
        <div class="col-md-8 mx-auto">
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title mb-0">考试结果</h4>
                </div>
                <div class="card-body">
                    <h5 class="text-center mb-4">{{ exam_room.name }}</h5>

                    <!-- 基本信息 -->
                    <div class="row mb-4">
                        <div class="col-md-6">
                            <p><strong>考试时间：</strong>{{ exam_room.start_time|date:"Y-m-d H:i" }}</p>
                            <p><strong>考试时长：</strong>{{ exam_room.duration }}分钟</p>
                        </div>
                        <div class="col-md-6">
                            <p><strong>提交时间：</strong>{{ exam_paper.submitted_at|date:"Y-m-d H:i:s" }}</p>
                            <p><strong>总分：</strong>{{ exam_paper.total_score }}</p>
                        </div>
                    </div>

                    <!-- 得分统计 -->
                    <div class="card mb-4">
                        <div class="card-body">
                            <h6 class="card-title">答题统计</h6>
                            <div class="row text-center">
                                <div class="col-4">
                                    <div class="h3">{{ total_questions }}</div>
                                    <div class="text-muted">总题数</div>
                                </div>
                                <div class="col-4">
                                    <div class="h3">{{ correct_questions }}</div>
                                    <div class="text-muted">正确题数</div>
                                </div>
                                <div class="col-4">
                                    <div class="h3">{{ accuracy_rate }}%</div>
                                    <div class="text-muted">正确率</div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- 题型分析 -->
                    <div class="card">
                        <div class="card-body">
                            <h6 class="card-title">题型分析</h6>
                            <div class="table-responsive">
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <th>题型</th>
                                            <th>总题数</th>
                                            <th>正确题数</th>
                                            <th>正确率</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>单选题</td>
                                            <td>{{ question_stats.single.total }}</td>
                                            <td>{{ question_stats.single.correct }}</td>
                                            <td>
                                                {% if question_stats.single.total > 0 %}
                                                {{ question_stats.single.correct|multiply:100|divide:question_stats.single.total|floatformat:1 }}%
                                                {% else %}
                                                -
                                                {% endif %}
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>多选题</td>
                                            <td>{{ question_stats.multiple.total }}</td>
                                            <td>{{ question_stats.multiple.correct }}</td>
                                            <td>
                                                {% if question_stats.multiple.total > 0 %}
                                                {{ question_stats.multiple.correct|multiply:100|divide:question_stats.multiple.total|floatformat:1 }}%
                                                {% else %}
                                                -
                                                {% endif %}
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>判断题</td>
                                            <td>{{ question_stats.judge.total }}</td>
                                            <td>{{ question_stats.judge.correct }}</td>
                                            <td>
                                                {% if question_stats.judge.total > 0 %}
                                                {{ question_stats.judge.correct|multiply:100|divide:question_stats.judge.total|floatformat:1 }}%
                                                {% else %}
                                                -
                                                {% endif %}
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="card-footer text-center">
                    <a href="{% url 'exam_system:exam_detail' exam_room.id %}" class="btn btn-primary">查看答题详情</a>
                    <a href="{% url 'exam_system:exam_list' %}" class="btn btn-secondary">返回考试列表</a>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
$(document).ready(function() {
    // 在这里可以添加图表展示等增强功能
});
</script>
{% endblock %}